$(function () {
    init_select_modal();
});

/**加载个人模板**/
function  init_select_modal() {
    //加载个人的模板
    $.post(ctx+"SaleHelp/getModalGrouplist",{cSaleMtype:1},function (r) {
        if (r.code == 0){
            var msg = r.msg;
            $("#select_acage").empty();
            $.each(msg,function (index,val) {
                var randomid= $JuXue.randomChart();
                var childeren = val.childrens;
                var ul  = "";
                $.each(childeren,function (index,val) {
                    ul += "<li uuid ="+val.cSaleUuid+"><a href=\"javascript:;\" onclick='selectModalDetail(this)'  class=\"p-3 p-l-15\">"+val.cSaleTitle+"</a></li>";
                });
                var selectGroup = "<div uuid='"+val.cSaleUuid+"'><h3 class=\"panel-title \">\n" +
                    "   <span class=\"height-25 text-left\">\n" +
                    "     <button class=\"accordion-toggle btn btn-link accordion-toggle-styled p-0 m-0 p-l-10 collapsed\"  data-toggle=\"collapse\" data-parent=\"#acage\" href='#"+randomid+"'>\n" +
                    "           <i class=\"fa fa-angle-right pull-left\"></i>\n" +
                    "     </button>\n" +
                    "     <button href=\"#\"   class=\"btn btn-link width-150 text-left\">"+val.cSaleTitle+"</button>\n" +
                    "   </span>\n" +
                    "</h3>\n" +
                    "<hr class=\"m-0\"/>\n" +
                    "<div id="+randomid+" class=\"panel-collapse collapse \">\n" +
                    " <ul class=\"nav nav-pills nav-stacked nav-sm panel-body p-t-5 m-0 p-b-5 \">\n" +ul+
                    " </ul>\n" +
                    "</div></div>";
                $("#select_acage").append(selectGroup);
            });
        }  else{
            $JuXue.n_danger("加载个人模板失败");
        }
    });
    //加载企业的模板
    $.post(ctx+"SaleHelp/getModalGrouplist",{cSaleMtype:0},function (r) {
        if (r.code == 0){
            var msg = r.msg;
            $("#select_qacage").empty();
            $.each(msg,function (index,val) {
                var randomid= $JuXue.randomChart();
                var childeren = val.childrens;
                var ul  = "";
                $.each(childeren,function (index,val) {
                    ul += "<li uuid ="+val.cSaleUuid+"><a href=\"javascript:;\" onclick='selectModalDetail(this)' class=\"p-3 p-l-15\">"+val.cSaleTitle+"</a></li>";
                });
                var selectGroup = "<div uuid='"+val.cSaleUuid+"'><h3 class=\"panel-title \">\n" +
                    "   <span class=\"height-25 text-left\">\n" +
                    "     <button class=\"accordion-toggle btn btn-link accordion-toggle-styled p-0 m-0 p-l-10 collapsed\" data-toggle=\"collapse\" data-parent=\"#qacage\" href='#"+randomid+"'>\n" +
                    "           <i class=\"fa fa-angle-right pull-left\"></i>\n" +
                    "     </button>\n" +
                    "     <button href=\"#\"  class=\"btn btn-link width-150 text-left\">"+val.cSaleTitle+"</button>\n" +
                    "   </span>\n" +
                    "</h3>\n" +
                    "<hr class=\"m-0\"/>\n" +
                    "<div id="+randomid+" class=\"panel-collapse collapse\">\n" +
                    " <ul class=\"nav nav-pills nav-stacked nav-sm panel-body p-t-5 m-0 p-b-5\">\n" +ul+
                    " </ul>\n" +
                    "</div></div>";
                $("#select_qacage").append(selectGroup);
            });
        }  else{
            $JuXue.n_danger("加载个人模板失败");
        }
    });
}

/**选择模板的详情**/
function selectModalDetail(btn) {
    var uuid = $(btn).parent().attr("uuid");
    if (uuid == ""){$JuXue.n_danger("加载模板的详细信息失败");return }
    $.post(ctx+"SaleHelp/getModalDetailPsrasetime",function (r) {
        $("#SelectModal").empty().append(r);
        selectModalDetailPrase(uuid);
    });

}
/**模板完成后 加载数据**/
function selectModalDetailPrase(uuid) {
    $.post(ctx+"SaleHelp/getModalDetail",{saleUUid:uuid},function (result) {
        if (result.code == 0){
            var data = result.msg;
            $("#modalTitle").val(data.cSaleTitle);$("#modalType").val(data.cSaleQtype);
            $("#modalDesc").val(data.cSaleDesc);$("#modaltime").val(data.oneParame);
            $("#modalCont").val(data.cSaleContent);
        }else{
            $JuXue.n_danger("初始化模板失败");
        }
    });
}
/**引用模板**/
function introduceModal() {
    var title = $("#modalTitle").val();
    $("#cPlanTitle").val(title);
    var time = $("#modaltime").val();
    $("#cPlanTime").val(time);
    var content =  $("#modalCont").val();
    $("#cPlanDesc").val(content);
    $('#sale_select_user').empty().modal('hide');
}




